package com.timoon.sample.dao;

import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.timoon.component.panel.jqgrid.JqGridParameter;
import com.timoon.sample.dao.model.Product;
import com.timoon.sample.dao.model.ProductExample;

@Repository
public class ProductDAOImpl extends SqlMapClientDaoSupport implements ProductDAO {

	/**
	 * This method was generated by Abator for iBATIS. This method corresponds to the database table product
	 * @abatorgenerated  Fri Jun 28 02:01:08 CST 2013
	 */
	public ProductDAOImpl() {
		super();
	}

	/**
	 * This method was generated by Abator for iBATIS. This method corresponds to the database table product
	 * @abatorgenerated  Fri Jun 28 02:01:08 CST 2013
	 */
	public void insert(Product record) {
		getSqlMapClientTemplate().insert("product.abatorgenerated_insert",
				record);
	}

	/**
	 * This method was generated by Abator for iBATIS. This method corresponds to the database table product
	 * @abatorgenerated  Fri Jun 28 02:01:08 CST 2013
	 */
	public int updateByPrimaryKey(Product record) {
		int rows = getSqlMapClientTemplate().update(
				"product.abatorgenerated_updateByPrimaryKey", record);
		return rows;
	}

	/**
	 * This method was generated by Abator for iBATIS. This method corresponds to the database table product
	 * @abatorgenerated  Fri Jun 28 02:01:08 CST 2013
	 */
	public int updateByPrimaryKeySelective(Product record) {
		int rows = getSqlMapClientTemplate().update(
				"product.abatorgenerated_updateByPrimaryKeySelective", record);
		return rows;
	}

	/**
	 * This method was generated by Abator for iBATIS. This method corresponds to the database table product
	 * @abatorgenerated  Fri Jun 28 02:01:08 CST 2013
	 */
	public List selectByExample(ProductExample example) {
		List list = getSqlMapClientTemplate().queryForList(
				"product.abatorgenerated_selectByExample", example);
		return list;
	}

	/**
	 * This method was generated by Abator for iBATIS. This method corresponds to the database table product
	 * @abatorgenerated  Fri Jun 28 02:01:08 CST 2013
	 */
	public Product selectByPrimaryKey(Integer id) {
		Product key = new Product();
		key.setId(id);
		Product record = (Product) getSqlMapClientTemplate().queryForObject(
				"product.abatorgenerated_selectByPrimaryKey", key);
		return record;
	}

	/**
	 * This method was generated by Abator for iBATIS. This method corresponds to the database table product
	 * @abatorgenerated  Fri Jun 28 02:01:08 CST 2013
	 */
	public int deleteByExample(ProductExample example) {
		int rows = getSqlMapClientTemplate().delete(
				"product.abatorgenerated_deleteByExample", example);
		return rows;
	}

	/**
	 * This method was generated by Abator for iBATIS. This method corresponds to the database table product
	 * @abatorgenerated  Fri Jun 28 02:01:08 CST 2013
	 */
	public int deleteByPrimaryKey(Integer id) {
		Product key = new Product();
		key.setId(id);
		int rows = getSqlMapClientTemplate().delete(
				"product.abatorgenerated_deleteByPrimaryKey", key);
		return rows;
	}

	/**
	 * This method was generated by Abator for iBATIS. This method corresponds to the database table product
	 * @abatorgenerated  Fri Jun 28 02:01:08 CST 2013
	 */
	public int countByExample(ProductExample example) {
		Integer count = (Integer) getSqlMapClientTemplate().queryForObject(
				"product.abatorgenerated_countByExample", example);
		return count.intValue();
	}

	/**
	 * This method was generated by Abator for iBATIS. This method corresponds to the database table product
	 * @abatorgenerated  Fri Jun 28 02:01:08 CST 2013
	 */
	public int updateByExampleSelective(Product record, ProductExample example) {
		UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
		int rows = getSqlMapClientTemplate().update(
				"product.abatorgenerated_updateByExampleSelective", parms);
		return rows;
	}

	/**
	 * This method was generated by Abator for iBATIS. This method corresponds to the database table product
	 * @abatorgenerated  Fri Jun 28 02:01:08 CST 2013
	 */
	public int updateByExample(Product record, ProductExample example) {
		UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
		int rows = getSqlMapClientTemplate().update(
				"product.abatorgenerated_updateByExample", parms);
		return rows;
	}

	/**
	 * This class was generated by Abator for iBATIS. This class corresponds to the database table product
	 * @abatorgenerated  Fri Jun 28 02:01:08 CST 2013
	 */
	private static class UpdateByExampleParms extends ProductExample {
		private Object record;

		public UpdateByExampleParms(Object record, ProductExample example) {
			super(example);
			this.record = record;
		}

		public Object getRecord() {
			return record;
		}
	}

	@javax.annotation.Resource(name="sqlMapClient")
	private SqlMapClient sqlMapClient;
	
	@PostConstruct
	public void addSqlMapClient() {
		// TODO Auto-generated constructor stub
		this.setSqlMapClient(sqlMapClient);
	}

	@Override
	public Integer countProductForPaging(JqGridParameter parameter) {
		// TODO Auto-generated method stub
		return (Integer) this.getSqlMapClientTemplate().queryForObject("product.countProductForPage", parameter);
	}

	@Override
	public List<Product> pagingPorduct(JqGridParameter parameter) {
		// TODO Auto-generated method stub
		return this.getSqlMapClientTemplate().queryForList("product.pageProduct", parameter);
	}

	@Override
	public List<Map<String, Object>> paginProductToMap(JqGridParameter parameter) {
		// TODO Auto-generated method stub
		return this.getSqlMapClientTemplate().queryForList("product.pageProductForMap",parameter);
	}
}